package com.ihelp.util;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ihelp.pojo.*;
import com.ihelp.service.OrderService;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


public class MyWrapper {
    public static MPJLambdaWrapper allRequestWrapper() {
        return new MPJLambdaWrapper<Request>()
                .selectAll(Request.class)
                .select(Hospital::getHospitalName, Hospital::getPosition)
                .select(HospitalDepartment::getDepartmentName)
                .select(User::getUsername, User::getPassword, User::getArea, User::getPhoneNumber, User::getBirthday, User::getCredit, User::getRate,
                        User::getAccompanyTime, User::getAccompanyNumber, User::getPersonalIntroduction, User::getNickname, User::getAvatarFileName)
                .select(ServiceType::getServiceName)
                .select(Area::getAreaName)
                .select(RequestStatus::getStatusName)
                .leftJoin(Hospital.class, Hospital::getId, Request::getHospitalId)
                .leftJoin(HospitalDepartment.class, HospitalDepartment::getId, Request::getHospitalDepartmentId)
                .leftJoin(User.class, User::getId, Request::getVisitorId)
                .leftJoin(ServiceType.class, ServiceType::getId, Request::getServiceTypeId)
                .leftJoin(Area.class, Area::getId, Request::getAreaId)
                .leftJoin(RequestStatus.class,RequestStatus::getId,Request::getStatusId)
                .orderByAsc(Request::getId);
    }

    public static MPJLambdaWrapper allOrderWrapper() {
        return new MPJLambdaWrapper<Order>()
                .selectAll(Order.class)
                .selectAs("visitor",User::getNickname,OrderDTO::getVisitorNickname)
                .selectAs("visitor", User::getAvatarFileName,OrderDTO::getVisitorAvatarFileName)
                .selectAs("accompanyer",User::getNickname,OrderDTO::getAccompanyerNickname)
                .selectAs("accompanyer",User::getAvatarFileName,OrderDTO::getAccompanyerAvatarFileName)
                .select(Hospital::getHospitalName, Hospital::getPosition)
                .select(HospitalDepartment::getDepartmentName)
                .select(ServiceType::getServiceName)
                .select(OrderStatus::getStatusName)
                .select(EvaluateLevel::getLevelName)
                .leftJoin(User.class,"visitor",User::getId,Order::getVisitorId)
                .leftJoin(User.class,"accompanyer",User::getId,Order::getAccompanyerId)
                .leftJoin(Hospital.class,Hospital::getId,Order::getHospitalId)
                .leftJoin(HospitalDepartment.class,HospitalDepartment::getId,Order::getHospitalDepartmentId)
                .leftJoin(ServiceType.class,ServiceType::getId,Order::getServiceTypeId)
                .leftJoin(OrderStatus.class,OrderStatus::getId,Order::getOrderStatusId)
                .leftJoin(EvaluateLevel.class,EvaluateLevel::getId,Order::getVisitorEvaluateLevelId)
                ;
    }
}
